import { defineConfig } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import { resolve } from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [uni()],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
      '@/components': resolve(__dirname, 'src/components'),
      '@/pages': resolve(__dirname, 'src/pages'),
      '@/utils': resolve(__dirname, 'src/utils'),
      '@/api': resolve(__dirname, 'src/api'),
      '@/store': resolve(__dirname, 'src/store'),
      '@/static': resolve(__dirname, 'src/static'),
      '@/types': resolve(__dirname, 'src/types'),
      '@/config': resolve(__dirname, 'src/config'),
      '@/mock': resolve(__dirname, 'src/mock'),
      '@/styles': resolve(__dirname, 'src/styles'),
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        api: 'modern-compiler', // 使用现代编译器
        additionalData: `@import "@/styles/variables.scss";`,
        silenceDeprecations: ['legacy-js-api', 'import'] // 抑制弃用警告
      }
    }
  },
  server: {
    host: '0.0.0.0',
    port: 8080,
    open: false, // 关闭自动打开浏览器
    cors: true,
    // 移除代理配置，直接使用请求中的完整URL
  },
  build: {
    target: 'es6',
    cssTarget: 'chrome61',
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: false, // 保留console用于调试
        drop_debugger: false
      }
    },
    rollupOptions: {
      output: {
        manualChunks: undefined // 禁用代码分割以避免小程序兼容性问题
      }
    }
  },
  optimizeDeps: {
    exclude: ['@dcloudio/uni-mp-weixin'] // 排除微信小程序依赖
  },
  });
